<template>
    <div class="app-container">
        <el-form ref="form" :model="form" label-width="160px">
            <el-form-item label="企业名称">
                <el-input v-model="form.name"/>
            </el-form-item>
            <el-form-item label="企业名称（英文）">
                <el-input v-model="form.nameEn"/>
            </el-form-item>
            <el-form-item label="统一社会信用代码">
                <el-input v-model="form.uscc"/>
            </el-form-item>
            <el-form-item label="企业法人">
                <el-input v-model="form.legalName"/>
            </el-form-item>
            <el-form-item label="联系人">
                <el-input v-model="form.contact"/>
            </el-form-item>
            <el-form-item label="电话">
                <el-input v-model="form.phone"/>
            </el-form-item>
            <el-form-item label="传真">
                <el-input v-model="form.fax"/>
            </el-form-item>
            <el-form-item label="注册资金">
                <el-input v-model="form.regCash"/>
            </el-form-item>
            <el-form-item label="企业币种">
                <el-input v-model="form.regCurrency"/>
            </el-form-item>
            <el-form-item label="组织性质代码">
                <el-select v-model="form.organizationCode" placeholder="请选择">
                    <el-option v-for="item in options.organizationCode" :key="item.value" :label="item.label"
                               :value="item.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="注册地">
                <el-cascader v-model="form.regionCode" :options="regions" @change="onRegionChange"></el-cascader>
            </el-form-item>
            <el-form-item label="企业地址">
                <el-input v-model="form.address"/>
            </el-form-item>
            <el-form-item label="企业地址（英文）">
                <el-input v-model="form.addressEn"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">提交</el-button>
                <el-button @click="$router.back()">返回</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import request from '../../utils/request';
    import regions from '../../utils/region';
    import { mapGetters } from 'vuex';

    export default {
        name: "Edit",
        computed: {
            ...mapGetters([
                'options'
            ])
        },
        data () {
            return {
                form: {
                    name: '',
                    nameEn: '',
                    uscc: '',
                    legalName: '',
                    contact: '',
                    phone: '',
                    tel: '',
                    fax: '',
                    people: '',
                    regCash: '',
                    regCurrency: '',
                    organizationCode: '',
                    regionCode: [],
                    address: '',
                    addressEn: '',
                },
                regions
            };
        },
        mounted () {
            request({
                url: `api/company/${this.$route.params.id}`
            }).then(res => {
                this.form = res.data;
            });
        },
        methods: {
            onSubmit () {
                request({
                    url: `/api/company/edit/${this.$route.params.id}`,
                    method: 'post',
                    data: this.form
                }).then(() => {
                    this.$router.push({path: '/company'});
                });
                this.$message('submit!');
            },
            onRegionChange (val) {
                console.log(val);
            }
        }
    };
</script>

<style scoped>

</style>
